package config

import (
	"flag"
	"fmt"
	"gopkg.in/yaml.v3"
	"io/ioutil"
	"path/filepath"
	"runtime"
	"shop-common/library/config"
)

var Config *config.Application
var flagEnv = flag.String("env", "dev", "set exec environment eg: dev,test,prod")

func init() {
	_, b, _, _ := runtime.Caller(0)
	Root := filepath.Join(filepath.Dir(b), "./")

	flag.Parse()

	bytes, err := ioutil.ReadFile(Root + fmt.Sprintf("/application-%s.yaml", *flagEnv))
	if err != nil {
		panic(err)
	}
	if err = yaml.Unmarshal(bytes, &Config); err != nil {
		panic(err)
	}
}
